package com.onstar.cn.common.util;

import android.os.Handler;
import android.os.Looper;

/**
 * 
 * @ClassName: MyPost 
 * @Description: post到主线程执行
 * @author Wanjin Chen
 * @date 2013-12-30 下午2:30:00    
 */
public class MyPost {
	/**
	 * post一个runnable到主线程
	 * 
	 * @param runnable
	 * @return
	 */
	public static boolean post(Runnable runnable) {
		if (Looper.myLooper() == Looper.getMainLooper()) {
			runnable.run();
			return true;
		} else {
			Handler handler = new Handler(Looper.getMainLooper());
			return handler.post(runnable);
		}

	}

	/**
	 * post一个runnable到主线程
	 * 
	 * @param runnable
	 * @param delayMillis
	 *            时间
	 * @return
	 */
	public static boolean postDelayed(Runnable runnable, long delayMillis) {
		if (Looper.myLooper() == Looper.getMainLooper()) {
			runnable.run();
			return true;
		}
		Handler handler = new Handler(Looper.getMainLooper());
		return handler.postDelayed(runnable, delayMillis);
	}
}